<template>
    <div class="user_conter">
        <div class="user_img">
            <img src="https://yanxuan.nosdn.127.net/static-union/164793255107785e.png" alt="">
        </div>
        <div class="userinfo">
            <van-form @submit="onSubmit">
                <van-cell-group inset>
                    <van-field v-model="phone" name="用户名" label="用户名" placeholder="用户名"
                        :rules="[{ required: true, message: '请填写用户名' }]" />
                    <van-field v-model="password" type="password" name="密码" label="密码" placeholder="密码"
                        :rules="[{ required: true, message: '请填写密码' }]" />
                </van-cell-group>
                <div class="twoname"><span><router-link to="/Logon" style=" color: #c9c9c9;">注册账号</router-link></span>
                    <span>忘记密码</span></div>
                <div style="margin: 16px;">
                    <van-button round block type="primary" native-type="submit">
                        提交
                    </van-button>
                </div>
            </van-form>
        </div>
        <div class="gologin"><router-link to="/Login" style="color: #c9c9c9;">其他登入方式></router-link></div>
    </div>
</template>

<script  setup lang='ts'>
import { ref, watch } from 'vue';
import { useUserInfoStore } from '../../../stores/userInfo';
import { useRoute, useRouter } from 'vue-router'
const redirect = ref('')
const route = useRoute()
const router = useRouter()
const userInfoStore = useUserInfoStore()

const phone = ref('17169099966');
const password = ref('111111');
const onSubmit = async () => {
    // const { username, password } = loginForm.value
    try {
        let res = await userInfoStore.login(phone.value, password.value) // 发送调用登录请求
       
        router.push({ path: redirect.value || '/Person' }) // 跳转页面
        
        
    } finally {
        // loading.value = false
    }
};
watch(route, () => {
    redirect.value = route.query && route.query.redirect as string
}, { immediate: true })
</script>

<style scoped lang="less">
.user_conter {
    width: 100%;
    min-height: 100%;
    padding: 0 10px;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    align-items: center;

    .user_img {
        width: 134px;
        height: 45px;
        text-align: center;
        margin-top: 50px;

        img {
            width: 100%;
            height: 100%;
        }
    }

    .userinfo {
        margin-top: 80px;

        .twoname {
            display: flex;
            font-size: 12px;
            justify-content: space-between;
            color: #c9c9c9;
            margin-top: 10px;
            padding: 0 27px;
            box-sizing: border-box;
        }
    }

    .gologin {
        width: 100%;
        height: 20px;
        margin-top: 50px;
        text-align: center;
        font-size: 12px;
    }
}
</style>